<template>
	<view class="outer-container">
		
		
		<uni-nav-bar
		v-if="userInfo && userInfo.vip"
		statusBar="true"
			shadow="true"
			backgroundColor="#e8b768"
			color="#fff"
			title="香哈菜谱大全">
		</uni-nav-bar>
		
		
		<uni-nav-bar statusBar="true"
		v-else
			shadow="true"
			backgroundColor="#ee7b2d"
			color="#fff"
			title="香哈菜谱大全">
		</uni-nav-bar>
		
	
		

		<!-- 搜索框 -->
		<input type="text"
			value=""
			class="search-bar"
			placeholder="共有857142道菜"
			 data-name="今天想吃啥"
			@tap="toMenuSearch"
			/>
		<!-- 首页大轮播图 -->
		<swiper class="home-swiper-one"
			:indicator-dots="true"
			:autoplay="true"
			:interval="3000"
			:duration="1000">
			<swiper-item v-for="item in swiperData"
				:key="item._id">
				<view class="swiper-item">
					<image :src="item.image_src"
						mode=""></image>
				</view>
			</swiper-item>
		</swiper>

		<!-- 不同菜品菜系选择区 -->
		<view class="menu-types">
			<view class="type-item"
				v-for="item in catItems.slice(0,-1)"
				:key="item._id"
				:data-name="item.name"
				@tap="toMenuSearch"
				>
				<image :src="item.image_src"
					mode=""></image>
				<text>{{item.name}}</text>
			</view>

			<view class="type-item"
				@tap="toMenuCategory">
				<image :src="catItems[catItems.length-1].image_src"
					mode=""></image>
				<text>{{catItems[catItems.length-1].name}}</text>
			</view>

		</view>

		<view class="wrapper-one">
			<view class="left">
				<swiper class="home-swiper-two"
					:indicator-dots="true"
					:autoplay="true"
					:interval="3000"
					:duration="1000"
					v-for="item in floorsData.slice(0,1)"
					:key="item.floor_title">
					<swiper-item v-for="img in item.floor_imgs"
						:key="img">
						<view class="swiper-item">

							<text class="swiper-title"
								:key="img">{{item.floor_title.replace(/"/g,'')}}</text>
							<image :src="img"
								mode=""
								:key="img"></image>
						</view>
					</swiper-item>

				</swiper>
			</view>

			<view class="right">
				<view class="right-item"
					v-for="item in floorsData.slice(1,3)"
					:key="item.floor_title">
					<text class="swiper-title">{{item.floor_title.replace(/"/g,'')}}</text>
					<image :src="item.floor_imgs[0]"
						mode=""></image>
				</view>

			</view>
		</view>

		<view class="wrapper-two">
			<view class="wt-item"
				v-for="item in homeRecommend"
				:key="item._id">
				<image :src="item.coverpic"
					mode=""></image>
				<text>{{item.name}}</text>
				<view class="item-row">
					<view class="row-item">
						<text>{{item.pageview}}</text>
						<image src="../../static/img/caipusousuo_slices/mengbanzu278.png"
							mode=""></image>
					</view>
					<view class="row-item">
						<text>{{item.collections < 0 ? item.collections * -1 : item.collections}}</text>
						<image src="../../static/img/home/favorite.png"
							mode=""></image>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import getLatestUserInfo from '../../utils/getLatestUserInfo.js';
	export default {
		data() {
			return {
				swiperData: [],
				catItems: [],
				floorsData: [],
				homeRecommend: [],
				userInfo:null
			}
		},
		onLoad() {
			this.getInitData();
			// this.userInfo = getApp().globalData.userInfo;
		},
		onShow(){
			this.getUserInfo();
		},
		// onReady() {
		// 	this.userInfo = getApp().globalData.userInfo;
		// },
		methods: {
			
			async getUserInfo(){
					let res = await getLatestUserInfo();
					if(res.code){
						this.userInfo = res.data;
					}
			},
			toMenuCategory() {
				uni.navigateTo({
					url: '../menu-category/menu-category'
				})
			},
			
			toMenuSearch(e){
				uni.navigateTo({
					url: '/pages/menu-search/menu-search?searchTip=' + e.currentTarget.dataset.name,
				})
				
			},

			async getInitData() {
				this.getSwiperData();
				this.getCatItems();
				this.getFloorsData();
				this.getHomeRecommend();
			},
			async getSwiperData() {
				let { message: res } = await this.$api.home.getSwiperData();
				this.swiperData = res;
			},
			async getCatItems() {
				let { message: res } = await this.$api.home.getCatItems();
				this.catItems = res;
			},
			async getFloorsData() {
				let { message: res } = await this.$api.home.getFloorsData();
				this.floorsData = res;
			},
			async getHomeRecommend() {
				let { message: res } = await this.$api.home.getHomeRecommend();
				this.homeRecommend = res;
			}

		}
	}
</script>

<style lang="scss"
	scoped>
	.search-bar {
		width: 686rpx;
		height: 74rpx;
		border-radius: 74rpx;
		margin: 12rpx auto;
		box-shadow: $uni-box-shadow-header;
		// background-color: royalblue;
		background-image: url(../../static/img/caipusousuo_slices/mengbanzu%202.png);
		background-repeat: no-repeat;
		background-position: 20rpx 20rpx;
		text-align: center;
		font-size: 28rpx;
	}

	.home-swiper-one {
		width: 686rpx;
		height: 304rpx;
		margin: 24rpx auto;

		// &:before {
		// 	content: "";
		// 	overflow: hidden;
		// }

		.swiper-item {
			width: 100%;
			height: 100%;

			image {
				width: 100%;
				height: 100%;
				border-radius: $uni-border-radius-base;
			}
		}
	}

	.menu-types {
		display: flex;
		flex-wrap: wrap;
		width: 686rpx;
		height: 304rpx;
		margin: 24rpx auto;

		.type-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			// box-sizing: border-box;
			width: 72rpx;
			height: 100rpx;
			margin-right: 80rpx;
			margin-bottom: 28rpx;
			// padding: 5rpx 10rpx;
			// box-shadow: $uni-box-shadow-header;

			&:nth-of-type(5n) {
				margin-right: 0;
			}

			image {
				width: 60rpx;
				height: 60rpx;
				margin-bottom: 10rpx;
			}

			text {
				font-size: 24rpx;
				color: $uni-text-color-1;
			}
		}

		// align-items: center;
	}

	.wrapper-one {
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 686rpx;
		height: 304rpx;
		margin: 24rpx auto;

		.left {
			width: 334rpx;
			height: 362rpx;

			.home-swiper-two {
				width: 100%;
				height: 100%;
				box-shadow: $uni-box-shadow-header;
				border-radius: $uni-border-radius-lg;

				.swiper-item {
					width: 100%;
					height: 100%;
					position: relative;

					.swiper-title {
						position: absolute;
						top: 14rpx;
						left: 14rpx;
						width: 164rpx;
						height: 56rpx;
						text-align: center;
						line-height: 56rpx;
						font-size: 30rpx;
						color: #fff;
						background-color: #d86f32;
						border-radius: 8rpx;
						opacity: 0.63;
					}

					image {
						width: 100%;
						height: 100%;
						border-radius: $uni-border-radius-lg;
					}
				}
			}
		}

		.right {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			align-items: center;
			width: 332rpx;
			height: 362rpx;
			

			.right-item {
				position: relative;
				

				.swiper-title {
					position: absolute;
					top: 14rpx;
					left: 14rpx;
					width: 164rpx;
					height: 56rpx;
					text-align: center;
					line-height: 56rpx;
					font-size: 30rpx;
					color: #fff;
					background-color: #d86f32;
					border-radius: 8rpx;
					opacity: 0.63;
				}

				image {
					width: 332rpx;
					height: 176rpx;
					border-radius: $uni-border-radius-lg;
				}
			}

		}
	}

	.wrapper-two {
		display: flex;
		flex-wrap: wrap;
		width: 686rpx;
		height: 700rpx;
		margin: 48rpx auto;

		.wt-item {
			display: flex;
			flex-direction: column;
			justify-content: space-around;
			align-items: center;
			width: 336rpx;
			height: 332rpx;
			margin-right: 14rpx;
			margin-bottom: 36rpx;

			&:nth-of-type(2n) {
				margin-right: 0;
			}

			image {
				width: 334rpx;
				height: 248rpx;
				border-radius: $uni-border-radius-lg;
			}

			text {
				width: 334rpx;
				text-align: left;
				font-size: 30rpx;
				color: $uni-text-color-1;
			}

			.item-row {
				width: 334rpx;
				display: flex;
				align-items: center;

				.row-item {
					// width: 334rpx;
					display: flex;
					align-items: center;
					margin-right: 60rpx;

					text {
						width: fit-content;
						font-size: 22rpx;
						color: #aaa;
						margin-right: 14rpx;
					}

					image {
						width: 24rpx;
						height: 24rpx;
					}
				}
			}
		}
	}
</style>
